﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Project.Teller
{
    public partial class OrderTeller : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataPOFDataContext db = new DataPOFDataContext();
            string acc = (from x in db.AccountLogins where x.Username == Session["username"].ToString() select x.FullName).FirstOrDefault();
            Label1.Text = acc;
            int ID = (from x in db.CustomerOrders select x.ID).Count();
            TextBox1.Text = Convert.ToString(ID + 1);
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Session["username"] = null;
            Response.Cache.SetNoStore();
            Response.CacheControl = "no-cache";
            Response.Redirect("../Home/Login.aspx");
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            DataPOFDataContext data = new DataPOFDataContext();

            // Add new Customer to data

            CustomerOrder customerOrder = new CustomerOrder();
            customerOrder.ID = Convert.ToInt32(TextBox1.Text);
            customerOrder.Name = TextBox2.Text;
            customerOrder.IdentityCard = Convert.ToInt32(TextBox6.Text);
            customerOrder.Address = TextBox3.Text;
            customerOrder.Phone = Convert.ToInt32(TextBox4.Text);
            customerOrder.Email = TextBox5.Text;
            // Add

            try
            {
                data.CustomerOrders.InsertOnSubmit(customerOrder);            

            }

            catch (Exception ex)
            {

                //MessageBox.Show(ex.Message);

            }

            finally
            {

                // Submit to data

                data.SubmitChanges();

            }
            Response.Redirect("../Teller/CreateOrder.aspx");
        }


    }
}